import os
from dashscope import Generation

# 流式响应
msgs = [
    {'role': 'user', 'content': '西红柿炒鸡蛋怎么做'}
]

resp = Generation.call(
    api_key=os.getenv("DASH_SCOPE_API_KEY"),
    model="qwen-plus",
    messages=msgs,
    result_format="message",

    stream=True,  # 流
    incremental_output=True,  # 增量流式输出
)

# print(resp)

for res in resp:
    if res.status_code == 200:
        print(res.output.choices[0].message.content, end="")
    else:
        print("调取错误")
